package stores;

import models.Odontologo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;

import models.Obra_Social;

public class Dao_ObrasSociales {
	
	Dao_connection unicaConeccion=Dao_connection.getInstancia();
	
	
	 public Obra_Social getObraSocialApartirDeNombre (String Sigla){
		 Obra_Social OS = null;
		 try{
			 Connection connection = unicaConeccion.getConnection();
			 Statement stmt = connection.createStatement();
			 String query = "SELECT * FROM Obra_Social where sigla like " +"'" +Sigla+ "'";

			 ResultSet rs = stmt.executeQuery(query);

			 if (rs.next()){
				 String nombre = rs.getString("Nombre");
				 String sigla = rs.getString("Sigla");

				 OS = new Obra_Social(sigla,nombre); /*QUE HACEMOS CON LO DEL PLAN???*/
			 }

			 connection.close();

		 }catch(SQLException e){
			 e.printStackTrace();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		 return OS; 
	 }

	/*
	private String sigla;
	private String nombre;
	private String plan;
	
	public Vector<Obra_Social> getObrasSociales(){
		Obra_Social ooss;
		Vector<Obra_Social> obrasSociales = new Vector<Obra_Social>();
		
		
		try{
			Connection connection = unicaConeccion.getConnection();
			Statement stmt = connection.createStatement();
			
			String query2 = "SELECT * FROM Obra_Social";
			
			ResultSet rs = stmt.executeQuery(query2);
			
			while(rs.next()){
				sigla = rs.getString("Sigla");
				nombre = rs.getString("nombre");
				plan = rs.getString("#Plan");
				
				ooss = new Obra_Social(sigla,nombre,plan);
			}
			
		}
		catch(SQLException e){
			e.printStackTrace();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return obrasSociales;
		
		
	}
	*/
	
	public String getSiglaApartirDeNombre(String nombre){
		String sigla=null;
		try{
			Connection connection = unicaConeccion.getConnection();
			Statement stmt = connection.createStatement();
			String query = "SELECT Sigla FROM Obra_Social where nombre like " +"'" +nombre+ "'";
			
			
			ResultSet rs = stmt.executeQuery(query);
			
			if (rs.next())
			{
				sigla = rs.getString("Sigla");
			}
			
			connection.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
		return sigla;
		
	}
	
	

}
